package com.example.yiwei.crm.view.activity.healthActivity;

import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.AsyncTask;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.Toast;

import com.example.yiwei.crm.R;
import com.example.yiwei.crm.base.baseClass;
import com.example.yiwei.crm.dao.customerDao;
import com.example.yiwei.crm.dao.dockDao;
import com.example.yiwei.crm.dao_impl.customerDaoImpl;
import com.example.yiwei.crm.dao_impl.dockDaoImpl;
import com.example.yiwei.crm.data.GetDock;
import com.example.yiwei.crm.entity.CustomerMessageEntity;
import com.example.yiwei.crm.entity.dockingEntity;
import com.example.yiwei.crm.view.Class.listviewClass.AutoListView;
import com.example.yiwei.crm.view.Class.listviewClass.ListAdapter;
import com.example.yiwei.crm.view.Class.listviewClass.ListViewAdapter;
import com.example.yiwei.crm.view.Class.listviewClass.managerSelectListAdapter;
import com.example.yiwei.crm.view.activity.customerActivity.SimpleReceiveCustomerActivity;

import java.util.List;

public class managerSelectActivity extends AppCompatActivity {
private ListView lstv;
    private managerSelectListAdapter ladapter;
    private ImageView img_back,img_commit;
    List<dockingEntity> dockingEntityList;
    private String manager_name;
    private int manager_id;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_manager_select);
        lstv= (ListView) findViewById(R.id.manager_listview);
        img_back= (ImageView) findViewById(R.id.manager_select_img_back);
        img_commit= (ImageView) findViewById(R.id.manager_select_img_commit);
        img_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        lstv.setDivider(new ColorDrawable(Color.rgb(216, 216, 216)));
        lstv.setDividerHeight(1);
        lstv.setChoiceMode(ListView.CHOICE_MODE_SINGLE);

        new Thread(new Runnable() {
            @Override
            public void run() {
                dockDao dockDao=new dockDaoImpl();
                dockingEntityList=dockDao.queryManagerSpinnerMessage(baseClass.query_manager_url,null);
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        ladapter = new managerSelectListAdapter(managerSelectActivity.this,dockingEntityList);
                        lstv.setAdapter(ladapter);
                        ladapter.notifyDataSetChanged();

                    }
                });
            }
        }).start();
   img_commit.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        final List<Integer> list2 = managerSelectListAdapter.getIDs();
        for (int i=0;i<list2.size();i++){
            manager_id=list2.get(i);
        }
        final List<String> list3 = managerSelectListAdapter.getNAMEs();
        for (int i=0;i<list3.size();i++){
            manager_name=list3.get(i);
        }
      if(list2.size()==1){
           GetDock.create();
           GetDock.dockingEntity.setManager_id(manager_id);
           GetDock.dockingEntity.setManager(manager_name);
           if (GetDock.dockingEntity!=null){
               finish();
           }
       }else if (list2.size()==0){
           Toast.makeText(managerSelectActivity.this, "请选择负责人哦！", Toast.LENGTH_SHORT).show();
       }else  if (list2.size()>1) {
          Toast.makeText(managerSelectActivity.this, "只能选择一个负责人哦！", Toast.LENGTH_SHORT).show();
      }
    }
});
    }
}
